/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.utfpr.controlador;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.edu.utfpr.bean.Cliente;
import br.edu.utfpr.dao.DaoCliente;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author guardezi
 */
@Resource
public class ClienteController {

    private final Result result;
    private final DaoCliente dao;

    public ClienteController(Result result, DaoCliente dao) {
        this.result = result;
        this.dao = dao;
    }

    @Path("/cadastrocliente")
    public void cliente() {
        result.include("cadastrocliente", "Cadastro Cliente");
        result.include("clienteList", dao.lista());

    }

    @Path("/listaclientes")
    public List<Cliente> lista() {
        return dao.lista();
    }

    @Post
    @Path("/gravarCliente")
    public void cadastrar(Cliente c) {
        System.out.println("cpf:" + c.getCliCpf());
            dao.gravar(c);


        result.forwardTo(this).lista();

    }

    @Get
    @Path("/excluir/{cpf}")
    public void excluir(Long cpf) {
        dao.excluir(cpf);
        result.forwardTo(this).lista();
    }
}
